package com.sitech.portal.system.service.impl;

import com.sitech.ibnms.util.DesEncrypterIsmp;
import com.sitech.ibnms.util.IDUtil;
import com.sitech.portal.system.dao.ISendPasswordDao;
import com.sitech.portal.system.dao.ISysLogInmsgDao;
import com.sitech.portal.system.service.ISendPasswordService;

import java.util.HashMap;

public class SendPasswordServiceImpl implements ISendPasswordService {

    private ISysLogInmsgDao sysLogInmsgDao;
    private ISendPasswordDao sendPasswordDao;

    public void setSysLogInmsgDao(ISysLogInmsgDao sysLogInmsgDao) {
        this.sysLogInmsgDao = sysLogInmsgDao;
    }

    public void setSendPasswordDao(ISendPasswordDao sendPasswordDao) {
        this.sendPasswordDao = sendPasswordDao;
    }

    @Override
    public String insertSMSForPassword(String loginId) {
        HashMap<String,String>  map = sysLogInmsgDao.findUserinfo(loginId);
        if(map==null||map.get("LOGIN_PHONE")==null){
            System.out.println("忘记密码发短信====================="+"map==null||map.get(\"LOGIN_PHONE\")==null");
            return "0";
        }else{
            String id = IDUtil.randomEncodedUUID();
            HashMap<String,String> sms = new HashMap();
            sms.put("MESSAGE_ID",id);
            sms.put("SERIAL_NO",id);
            sms.put("MESSAGE_TO",map.get("LOGIN_PHONE"));
            DesEncrypterIsmp encrypter = new DesEncrypterIsmp();
            String password = encrypter.decrypt(map.get("LOGIN_PASSWD"));
            sms.put("MESSAGE_CONTENT","您的登录密码为:"+password);
            System.out.println("====================="+"开始插入");
            sendPasswordDao.insertSMSForPassword(sms);
        }
        return map.get("LOGIN_PHONE");
    }

}
